﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Shsc.Net.FrameWork.Common.Util;
using System.Collections;

namespace Shsc.Net.FrameWork.Common.Validator
{
    public class RequiredAttribute : BaseCheckAttribute
    {

        public RequiredAttribute()
        {
            this._messageId = "ERR_90001";
        }

        /// <summary>
        /// 必須Check方法
        /// </summary>
        /// <param name="msgId"></param>
        /// <param name="msgParams"></param>
        public RequiredAttribute(string msgId, params string[] msgParams)
        {
            this._messageId = msgId;
            this._msgParams = msgParams;
        }

        /// <summary>
        /// Check
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override string DoCheck(object obj, string fieldName)
        {
            if (obj == null || string.IsNullOrEmpty((string)obj))
            {
                IList<string> lisParam = new List<string>();
                lisParam.Add(fieldName);
                if (_msgParams != null)
                {
                    lisParam.Concat(_msgParams);
                }
                return MessageUtil.GetSingleMessage(this._messageId, lisParam.ToArray());
            }
            return string.Empty;
        }
    }
}
